// pages/Login/privacy.js
const Controllers = require('../controllers/Controller.js').controller;
const utils = require('../../utils/util.js');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    title: ''
  },
  listByType() {
    var that = this;
    Controllers.contentListByType({id: that.data.id}).then(res => {
      console.log('listByType--res==', res);
      const { code, data, desc } = res;
      const content = data.content.replace(/<img/g, '<img style="max-width: 100%;"');
      that.setData({
        content: content
      })
    })
  },
  getSwiperDetails() {
    var that = this;
    const id = that.data.id;
    const swiperList = wx.getStorageSync('swiperList') || [];
    const details = swiperList.find(d => d.id === id);
    const content = details && details.remark ? details.remark.replace(/<img/g, '<img style="max-width: 100%;"') : '';

    that.setData({
      content: content
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    if (!options.id) {
      wx.navigateBack()
    }
    that.setData({
      id: parseInt(options.id) || 0,
      title: options.title || '',
      type: options.type || ''
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    if (that.data.type === 'swiperDetails') {
      that.setData({
        title: '详情介绍'
      })
      that.getSwiperDetails();
    } else {
      that.listByType();
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    this.setData({
      id: '',
      title: ''
    })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    this.setData({
      id: '',
      title: ''
    })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})